package hk.m4s.lr.repair.test.ui.adapter;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import framework.common.Constant;
import framework.common.zanetwork.core.ResponseCallback;
import framework.utils.SharedPreferencesUtils;
import hk.m4s.lr.repair.test.R;
import hk.m4s.lr.repair.test.model.AddressModel;
import hk.m4s.lr.repair.test.model.CouponModel;
import hk.m4s.lr.repair.test.service.address.AddressService;
import hk.m4s.lr.repair.test.ui.user.AddAddressActivity;
import okhttp3.Response;

public class CouponListAdapter extends BaseAdapter {
	private Context context;
	public List<CouponModel> list;
	private LayoutInflater flater;
	public CouponListAdapter(Context context, List<CouponModel> list) {
		this.context = context;
		this.list = list;
		this.flater = LayoutInflater.from(context);
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder = null;

		if (convertView == null) {
			holder = new ViewHolder();
			convertView = flater.inflate(R.layout.list_item_coupon, null);
			holder.couponPrice = (TextView) convertView
					.findViewById(R.id.couponPrice);
			holder.couponName = (TextView) convertView
					.findViewById(R.id.couponName);
			holder.couponTime = (TextView) convertView
					.findViewById(R.id.couponTime);
			holder.couponRule = (TextView) convertView
					.findViewById(R.id.couponRule);
			convertView.setTag(holder);

		} else {
			holder = (ViewHolder) convertView.getTag();
		}
        if(list!=null) {
			CouponModel bean = list.get(position);
			holder.couponName.setText(bean.getCouponName());
			holder.couponPrice.setText("¥"+bean.getCouponPrice());
			holder.couponTime.setText(bean.getStartTime()+"至"+bean.getEndTime()+"有效");
			holder.couponRule.setText(bean.getCouponRule());
		}
		return convertView;
	}

	static class ViewHolder {
		public TextView couponPrice;
		public TextView couponName;
		public TextView couponTime;
		public TextView couponRule;
	}
}
